<?php 
	$per_page = 4;
	
	if(!isset($_GET['page']) || $_GET['page']<=0)
	{
		$page = 1; 	//Current page
	}
	else
	{
		$page = $_GET['page'];
	}

	if($page <= 1)
	{
		$start = 0;
	}
	else
	{
		$start = $page*$per_page - $per_page;
	}
	
	require_once('function/connectDB.php');
	
	$sql = 'SELECT * FROM email	';
	$num_rows = mysql_num_rows(mysql_query($sql));
	$num_pages = ceil($num_rows/$per_page);
	
	$sql .=  ' LIMIT '.$start.','.$per_page.'';
	
	$result = mysql_query($sql) or die("Can not query");
	
	?>
	<link rel="stylesheet" type="text/css" href="css/style.css" />
	<script type="text/javascript" src="jquery.min.js"></script>
	<script type="text/javascript" src="script.js"></script>
	<form name="Insert_Record" method="post">
		<input type="text" name="email" id="email" size="30" />
		<input type="button" name="insert" id="insert" value="Insert" />
	</form>
	<p name="notes" id="notes" />
	<div>
		<form name="formmail" id="formmail" method="post">
		<table>
			<tr>
				<td>ID</td>
				<td>Email</td>
				<td>Edit</td>
				<td>Delete</td>
			</tr>
		<?php
		while($rows = mysql_fetch_array($result))
		{
			?>
			<tr>
				<td><?php echo $rows['id'].'</br>'; ?></td>
				<td><?php echo $rows['email'].'</br>'; ?></td>
				<td>
					<a href='#' id="edit_<?php echo $rows['id'];?>" class="edit">Edit</a><br/>
				</td>
				<td>
					<input type="checkbox" id='del_<?php echo $rows['id']; ?>' name='del' value='<?php echo $rows['id'];?>' />
				</td>
			</tr>
			<?php
		}
		?>
			<tr>
					<td></td>
					<td></td>
					<td></td>
					<td><input type="button" name="delete" id="delete" value="Delete"></td>
			</tr>
		</table>
		</div>
		</form>
	</div>
	
	<!-- Light Box-->
	
	<div class="backdrop">fsfsd</div>
	<div class="box" align="center">
		<div class="close">x</div>
			Edit Email
			<form name="edit_lightbox" class="form" method="post" style="width:315px;height:120px" >
				<table>
					<tr>
						<td colspan="2" width="35%">Email :</td>
						<td  colspan="2" width="65%"><input type="text" id="edittext_lightbox" style="width:200"/></td>
					</tr>
					<tr>
						<td colspan="2"></td>
						<td width="50%"><input type="button" id="editbt_lightbox" value="OK" style="width:64"/></td>
						<td width="50%"><input type="button" id="cancelbt_lightbox" value="Cancel" /></td>
					</tr>
				</table>
			</form>
		<p id="notesedit" />
	</div>
	<!-- End Light Box -->
	<?php
	
	$prev = $page - 1;
	$next = $page + 1;
	
	echo '<br/>';
	if($prev>0)
	echo '<a href="?page='.$prev.'">Prev</a> ';
	
	$number = 1;
	for($number; $number <= $num_pages; $number++)
	{
		if($page == $number)
		{
			echo '<b>['.$number.']</b>';
		}
		else
		{
			echo '<a href="?page='.$number.'">'.$number.'</a> ';
		}
	}
	
	
	if($page<$num_pages)
	echo '<a href="?page='.$next.'">Next</a>';
?>